﻿{extend name="public:base" /}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <a href="{:url('doGoods')}" class="btn btn-primary btn-lg">新增</a>

                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="iconfont icon-chevron-up"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select class="form-control form-control-lg one_type" onchange="changeOneType(this)">
                                    <option value="0">请选择一级分类</option>
                                    {volist name="type_list" id="vo"}
                                    <option value="{$vo.id}" {:input('one_type_id') == $vo.id ? 'selected' : ''}>{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select class="form-control form-control-lg two_type">
                                    <option value="0">请选择二级分类</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <button type="button" class="btn btn-primary btn-lg screen-btn">搜索</button>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>商品名称</th>
                                <th>分类</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.name}</td>
                                <td>{$vo.one_type_name} - {$vo.two_type_name}</td>
                                <td>{:timeFormat($vo.create_time)}</td>
                                <td class="project-actions">
                                    <a href="{:url('doGoods', ['id' => $vo.id])}" class="btn btn-white btn-sm">
                                        <i class="iconfont icon-edit"></i> 编辑
                                    </a>
                                    <a href="{:url('delGoods', ['id' => $vo.id])}" class="btn btn-white btn-sm ajax-del">
                                        <i class="iconfont icon-trash"></i> 删除
                                    </a>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        {if !empty($list)}{$list->render()}{/if}
                    </div>

                </div>
            </div>
        </div>

    </div>
</div>

{/block}

{block name="js"}
<script>
    var type_list = {$type_list_json};

    // 搜索跳转后二级分类回显
    var one_type_id = "{:input('one_type_id')}";
    if(one_type_id) changeOneType(this, one_type_id);

    // 选中一级分类渲染二级分类
    function changeOneType(that, get_one_type_id = 0){
        var one_type_id = get_one_type_id ? get_one_type_id : $(that).val();

        var option = "<option value='0'>请选择二级分类</option>";
        for (var i = 0; i < type_list.length; i++) {
            if (one_type_id == type_list[i].id) {
                var son_list = type_list[i].son_list;
                if (son_list.length > 0) {
                    son_list.forEach(function (val) {
                        var two_type_id = "{:input('two_type_id')}";
                        var selected = two_type_id == val.id ? "selected" : "";

                        option += "<option value='" + val.id + "' "+ selected +">" + val.name + "</option>"
                    })
                }
                break;
            }
        }
        $('.two_type').html(option)
    }
</script>
{/block}

